<?php
/**
 * 生成物品和材料ID的关系
 */
echo '<pre>';
$itemMat = array();

$list = C('item/item_list');
$itemList = array();
foreach ($list as $itemId => $value) {
	$itemList[$itemId] = $value['title'];
}

// 物品参数ID关联
$mat_type_list = array(
	'cook', //食品
	'drink', //饮料
	'furniture', //家具
//	'finery', //服饰
);
$main_mat_max = 40;//主材
$type_max = 49;//子类型
$sec_mat_max = 57;//辅材
$param_max = 67;//风格等参数
$param_type_list = array(
	40 => '主材',
	49 => '子类型',
	57 => '辅材',
	67 => '风格',
);
foreach ($mat_type_list as $name) {
	$cfgList = C('making/'.$name.'_param');
	$main_mat_list = array();
	$type_list = array();
	$sec_mat_list = array();
	$param_list = array();
	foreach ($G[$name.'_param_list'] as $id=>$title) {
		if ($id <= $main_mat_max) {
			$main_mat_list[$id] = $title;
		} elseif ($id <= $type_max) {
			$type_list[$id] = $title;
		} elseif ($id <= $sec_mat_max) {
			$sec_mat_list[$id] = $title;
		} else {
			$param_list[$id] = $title;
		}
	}
//	var_export($main_mat_list);
//	echo "\n";
//	var_export($type_list);
//	echo "\n";
//	var_export($sec_mat_list);
//	echo "\n";
//	var_export($param_list);
//	echo "\n=====================\n";
	
	
	
}

$arr = array();
for($i=1; $i<=23; $i++) {
	$arr[] = sprintf('%02d', $i);
}
//var_export($arr);
//exit;
$num = 4;
$ret = combination($arr, $num);
var_export($ret);

/**
 * 用于组合的数组
 * @param $arr
 * @param $num 取出的数量
 */
function combination($arr, $num, $s=array())
{
	$ret = array();
	if ($num == 0) {
		$len = count($s);
		$s = array_unique($s);
		if (count($s) == $len) {
			return array($s);
		} else {
			return array();
		}
	}
	$len = count($arr);
	$end = $len - $num;
	for ($i=0; $i<=$end; $i++) {
		$arg1 = $arr;
		array_shift($arg1);
		$arg2 = $num - 1;
		$arg3 = $s;
		$arg3[] = $arr[$i];
		$tmp = combination($arg1, $arg2, $arg3);
		$ret = array_merge($ret, $tmp);
	}
	return $ret;
}

//function combination(a,r,s)
//{
//    var ret = [];
//    s = s || [];
//    if(r == 0) {return [s];}
//    for(var i = 0; i <= a.length - r; i++){
//       ret = ret.concat(arguments.callee(a.slice(i+1), r-1, s.slice(0).concat(a[i])));
//    }
//    return ret;
//}


function get_param_type () {
	
}